﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace SQLDataTransferer.Common.Dialogs
{
    /// <summary>
    /// Interaction logic for MessageDialog.xaml
    /// </summary>
    public partial class MessageDialog : Window
    {       
        #region Events and Delegates

        private delegate void HandleMessageDialogDelegate(string title, string message, UIElement ctrl);

        #endregion

        #region Constructor(s)

        public MessageDialog(string title, string message)
        {
            InitializeComponent();

            this.Title = title;
            this.txtMessage.Text = message;
        }

        #endregion

        #region Methods
        
        public static void ShowDialog(string title, string message, UIElement ctrl)
        {
            if (!ctrl.Dispatcher.CheckAccess())
            {
                ctrl.Dispatcher.Invoke(new HandleMessageDialogDelegate(ShowDialog), title, message, ctrl);
                return;
            }

            Dialogs.MessageDialog.Show(title, message, ctrl);
        }

        public static void Show(string title, string message, UIElement ctrl)
        {
            MessageDialog dlg = new MessageDialog(title, message);
            dlg.Owner = (Window)ctrl;
            dlg.ShowDialog();
        }

        #endregion

        #region EventHandlers

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        #endregion
    }
}
